package com.zzyl.controller.customer;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.AddshijianDto;
import com.zzyl.dto.FenyeDto;
import com.zzyl.entity.fneye;
import com.zzyl.service.CanguanyuyueService;
import com.zzyl.vo.shijianVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/customer/reservation")
public class CanguanyuyueController {
    @Autowired
    private CanguanyuyueService canguanyuyueService;

    @GetMapping("/cancelled-count")
    public ResponseResult<Integer> chanxun(Long memberId) {
        // 调用 Service 层方法获取取消预约次数
        int cancelledCount = canguanyuyueService.chanxun9(memberId);

        return ResponseResult.success(cancelledCount);
    }

    //2.1 查询取消预约数量
    @GetMapping("/countByTime")
    public ResponseResult<List<shijianVo>> getcountByTime(@RequestParam("time") Long time) {

        List<shijianVo> list = canguanyuyueService.getcountByTime(time);
        return ResponseResult.success(list);
    }

    //2.3 新增预约
    @PostMapping
    public ResponseResult<Void> add(@RequestBody AddshijianDto dto) {

        canguanyuyueService.add(dto);
        return ResponseResult.success();
    }

    /*
     * 2.4 分页查询预约
     * */
    @GetMapping("/page")
    public ResponseResult<PageResponse> getPage(FenyeDto dto) {
        PageResponse pageResponse = canguanyuyueService.getPage(dto);
        return ResponseResult.success(pageResponse);

    }

    /*
    * 2.5 取消预约
    * */
    @PutMapping("/{id}/cancel")
    public ResponseResult<Void> cancel(@PathVariable("id") Long id) {

        canguanyuyueService.cancel(id);
        return ResponseResult.success();
    }

}